import cv2
import numpy as np
from matplotlib import pyplot as plt

img = cv2.imread('d:\\test7.jpg')

kernel = np.ones((5, 5), np.float32) / 25

# cv.Filter2D(src, dst, kernel, anchor=(-1, -1))
# ddepth –desired depth of the destination image;
# if it is negative, it will be the same as src.depth();
# the following combinations of src.depth() and ddepth are supported:
# src.depth() = CV_8U, ddepth = -1/CV_16S/CV_32F/CV_64F
# src.depth() = CV_16U/CV_16S, ddepth = -1/CV_32F/CV_64F
# src.depth() = CV_32F, ddepth = -1/CV_32F/CV_64F
# src.depth() = CV_64F, ddepth = -1/CV_64F
# when ddepth=-1, the output image will have the same depth as the source.
# dst = cv2.filter2D(img, -1, kernel)

# blur = cv2.blur(img,(5,5))
# blur = cv2.GaussianBlur(img,(5,5),0)
blur = cv2.bilateralFilter(img,9,75,75)
median = cv2.medianBlur(img,5)

# plt.subplot(121),plt.imshow(img),plt.title('Original')
# plt.xticks([]), plt.yticks([])
# plt.subplot(122),plt.imshow(blur),plt.title('Averaging')
# plt.xticks([]), plt.yticks([])
# plt.show()


cv2.namedWindow('image', cv2.WINDOW_NORMAL)
cv2.resizeWindow('image', 800, 600)  # 定义frame的大小
cv2.imshow('image', blur)
cv2.waitKey(0)
cv2.destroyAllWindows()